/*******************************************************************************
* CSCI321 Major Project 2010 - University of Wollongong                        *
********************************************************************************
* Program:		WeaveEdit                                              *
* Authors:		Simon Allen (Student#: 3457527, Unix: sa655)           *
*			Scott Bellis (Student#: 3479110, Unix: sjb900)         *
*			Jason Benger (Student#: 3454137, Unix: jb960)          *
*			Timothy Newmarch (Student#: 3459263 Unix: tgn336)      *
*			Benjamin Richardson (Student# 3467752, Unix: bjr401)   *
* Supervisor:		Daniel F. Saffioti                                     *
* Modified:		28/10/2010                                             *
* Description:		WeaveEdit is a highly portable collaborative text      *
*			editor and word processor, allowing several users to   *
*			read and edit multiple documents at the same time.     *
*			It is available for Mac OS X, Windows and Linux,       *
*			utilising Nokia's Qt development framework.            *
*******************************************************************************/


#ifndef WELCOMESCREEN_H
#define WELCOMESCREEN_H

#include "Editor/editor.h"

#include <QWidget>
#include <QPainter>
#include <QStyledItemDelegate>
#include <QListWidgetItem>
#include <QTreeWidgetItem>
#include <QSettings>


namespace Ui
{
	class WelcomeScreen;
}

/**
  * Simple list item formatting class used by WelcomeScreen so that we can use HTML in the items.
  */
class HtmlDelegate : public QStyledItemDelegate
{
	protected:
		void paint(QPainter *painter, const QStyleOptionViewItem &option,
			   const QModelIndex &index) const;
		QSize sizeHint(const QStyleOptionViewItem &option,
			       const QModelIndex &index) const;
};

/**
  * Simple screen the user sees when loading WeaveEdit. Has lists of help docs and recent files/sessions.
  */
class WelcomeScreen : public QWidget
{
	Q_OBJECT

	public:
		const static int MAX_RECENT_SESSIONS;
		const static int MAX_RECENT_TEXT_FILES;
		const static int MAX_RECENT_FORMATTED_FILES;

		static WelcomeScreen *getInstance()
		{
			if (!instance)
				instance = new WelcomeScreen();

			return instance;
		}

		~WelcomeScreen();

		void addRecentFile(const QString fileName, const Editor::Type type);
		void addRecentSession(const QString sessionName, const QString fileName);
		void setupHelpList();

	public slots:
		void dispatchRecentSession(QTreeWidgetItem *item);
		void dispatchRecentFile(QTreeWidgetItem *item);
		void dispatchHelp(QTreeWidgetItem *item);
		void loadRecentSessions();
		void loadRecentFiles();
		void saveRecentSessions();
		void saveRecentFiles();

	signals:
		void recentSessionSelected(const QString) const;
		void recentFileSelected(const QString) const;

	protected:
		WelcomeScreen(QWidget *parent = 0);

	private:
		Ui::WelcomeScreen *ui;
		static WelcomeScreen *instance;
		HtmlDelegate *recentSessionsListDelegate;
		HtmlDelegate *recentFilesListDelegate;
		HtmlDelegate *helpListDelegate;
		QTreeWidgetItem *textFilesSection;
		QTreeWidgetItem *formattedFilesSection;
		QTreeWidgetItem *helpHome;
		QTreeWidgetItem *helpUserManual;
		QTreeWidgetItem *helpTechManual;
		QSettings *settings;
};

#endif // WELCOMESCREEN_H
